﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;

namespace WPFExcelReport
{
    public partial class TAB50
    {
        TGBBS13 control;
        public TAB50()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABPOS();
            DataContext = MV;
            IsMasterFromMV = true;
            InitializeComponent();

        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
            Load();
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            if (dwMain == null)
            {
            }
            if (dwMaster != null)
            {
                PRART = dwMaster["ABPART"].ToString() + Helper.Right("   " + dwMaster["ABPVAR"].ToString(), 3) + dwMaster["ABPFARBE"].ToString();
                FABP = "V" + dwMaster["ABPAUFKRS"].ToString() + dwMaster["ABPAUFLFD"].ToString()
                    + dwMaster["ABPAUFPOS"].ToString() + dwMaster["ABPAUFART"].ToString() + PRART;
            }
        }
        public void Load()
        {
            if (vm == null)
                return;
            if (AUF == null)
                return;
            if (AUF.Length < 1)
                return;
            DataRow dwData = TBMain.NewRow();
            string ordertype = Helpers.Helper.Left(AUF, 1);
            dwData["ABPMANDANT"] = app.Mandant;
            dwData["ABPAUFKRS"] = AUF.Substring(1, 2);
            dwData["ABPAUFLFD"] = AUF.Substring(3, 6);
            dwData["ABPAUFPOS"] = AUF.Substring(9, 3);
            DataSet SResult = TMV.QueryABPOS(dwData, 31);
            MergeData(SResult, true);
            MessageInfo msgs = new MessageInfo();
            string msg = "";
            msgs.MSGTYPE = "JOBADD";
            msgs.Sender = this.RUNID;
            msgs.ACTION = "JOBADD";
            msgs.AUFTYP = "V";
            foreach (DataRow row in TBMain.Rows)
            {
                msgs.KRS = row["ABPAUFKRS"].ToString();
                msgs.LFD = row["ABPAUFLFD"].ToString();
                msgs.POS = row["ABPAUFPOS"].ToString();
                msgs.P1 = row["ABPAUFART"].ToString();
                msgs.P2 = row["ABPPOSTYP"].ToString();
                VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", dwMaster, msg, msgs);
            }
        }

        private void ShowDetail_Click(object sender, RoutedEventArgs e)
        {
            if (!IsShowOutPut)
            {
                IsShowOutPut = true;
                return;
            }
            IsShowOutPut = false;
        }
    }
}
